import Vue from 'vue'
import VueRouter from 'vue-router'
import {	Message} from 'element-ui'
Vue.use(VueRouter)

const routes = [{
	path: '/',
	name:'home',
	component: () => import('../views/Home.vue'),
	children: [
		{
			path: '/diagramofbed',
			name:'diagramofbed',
			component: () => import('../views/beds/diagramofbed.vue')
		},
		{
			path: '/bedmanagement',
			name:'bedmanagement',
			component: () => import('../views/beds/bedmanagement.vue')
		},
		{
			path: '/checkin',
			name:'checkin',
			component: () => import('../views/clientele/checkin/checkin.vue')
		},
		{
			path: '/clientinformation',
			name:'clientinformation',
			component: () => import('../views/clientele/clientinformation/clientinformation.vue')
		},
		{
			path: '/liveregistration',
			name:'liveregistration',
			component: () => import('../views/clientele/liveregistration/liveregistration.vue')
		},
		{
			path: '/gotoregister',
			name:'gotoregister',
			component: () => import('../views/clientele/gotoregister/gotoregister.vue')
		},
		{
			path: '/calendar',
			name:'calendar',
			component: () => import('../views/dietary/calendar.vue')
		},
		{
			path: '/management',
			name:'management',
			component: () => import('../views/dietary/management.vue')
		},
		{
			path: '/nurselevel',
			name:'nurselevel',
			component: () => import('../views/nurse/nurselevel.vue')
		},
		{
			path: '/nurselevelcontent',
			component: () => import('@/views/nurse/nurselevelcontent'),
			name: 'nurselevelcontent',
			hidden: true,
		},
		{
			path: '/nursecontent',
			name:'nursecontent',
			component: () => import('../views/nurse/nursecontent.vue')
		},
		{
			path: '/nurserecord',
			name:'nurserecord',
			component: () => import('../views/nurse/nurserecord.vue')
		},
		{
			path: '/databasemaintenance',
			name:'databasemaintenance',
			component: () => import('../views/system/database/databasemaintenance.vue')
		},
		{
			path: '/staff',
			name:'staff',
			component: () => import('../views/system/staff/staff.vue')
		},
		{
			path: '/servicehouse',
			name:'servicehouse',
			component: () => import('../views/health/servicehouse/servicehouse.vue')
		},
		{
			path: '/serviceattention',
			name:'serviceattention',
			component: () => import('../views/health/serviceattention/serviceattention.vue')
		},{
			path: '/role',
			name:'role',
			component: () => import('../views/role/role.vue')
		},{
			path: '/permission',
			name:'permission',
			component: () => import('../views/permission/permission.vue')
		},{
			path: '/role-permission',
			name:'role-permission',
			component: () => import('../views/role/role-permission.vue')
		},{
			path: '/user',
			name:'user',
			component: () => import('../views/user/user.vue')
		}
		
		
	]
},{
	path:'/login',
	name:'Login',
	component: () => import('../views/login/login.vue'),
 }
]


const router = new VueRouter({
	mode: 'hash',
	base: process.env.BASE_URL,
	routes
})

router.beforeEach((to, from, next) => {
  if (to.path === '/login') {
    next();
  } else {
    let token = localStorage.getItem('Token');
	
    if (token == null || token == '') {
	  Message.error("请重新登录！");
      next('/login');
    } else {
      next();
    }
  }
});

export default router
